home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume6 / glib / part12 < prev    next >
Encoding:
Text File  |  1989-05-14  |  35.4 KB  |  1,277 lines

  1. Newsgroups: comp.sources.misc
  2. From: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  3. Subject: v06i113: glib part 12 of 15
  4. Reply-To: lee@uhccux.uhcc.Hawaii.Edu (Greg Lee )
  5.  
  6. Posting-number: Volume 6, Issue 113
  7. Submitted-by: lee@uhccux.uhcc.Hawaii.Edu (Greg Lee )
  8. Archive-name: glib/part12
  9.  
  10. #! /bin/sh
  11. # This is a shell archive.  Remove anything before this line, then unpack
  12. # it by saving it into a file and typing "sh file".  To overwrite existing
  13. # files, type "sh file -c".  You can also feed this as standard input via
  14. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  15. # will see the following message at the end:
  16. #        "End of archive 12 (of 15)."
  17. # Contents:  cz1.mnu
  18. # Wrapped by lee@uhccux on Sun May  7 00:40:19 1989
  19. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  20. if test -f 'cz1.mnu' -a "${1}" != "-c" ; then 
  21.   echo shar: Will not clobber existing file \"'cz1.mnu'\"
  22. else
  23. echo shar: Extracting \"'cz1.mnu'\" \(33418 characters\)
  24. sed "s/^X//" >'cz1.mnu' <<'END_OF_FILE'
  25. X/* $Id: cz1.mnu,v 1.6 89/05/06 17:13:14 lee Exp $
  26. X * GLIB - a Generic LIBrarian and editor for synths
  27. X *
  28. X * CZ-1 routines
  29. X * Mark Rinfret
  30. X * modified by Greg Lee
  31. X * $Log:    cz1.mnu,v $
  32. X * Revision 1.6  89/05/06  17:13:14  lee
  33. X * rel. to comp.sources.misc
  34. X * 
  35. X */
  36. X
  37. X#define OVERLAY1
  38. X
  39. X#include "glib.h"
  40. X#include <ctype.h>
  41. X
  42. X#ifdef AMIGA
  43. X#define CZ1
  44. X#else
  45. Xvoid sendmulti();
  46. X#endif
  47. X
  48. X#include "cz.h"
  49. X
  50. X#define RING    1
  51. X#define NOISE   2
  52. X
  53. Xchar *visnum(), *visonoff();
  54. Xchar *visczdet(), *visczflag(), *visczline(), *visczmod(), *viscznum2();
  55. X/* char *visczoct(); */
  56. X
  57. Xstatic void getenvelope();
  58. Xstatic void getwaveforms();
  59. Xstatic void setenvelope();
  60. Xstatic void setwaveforms();
  61. X
  62. X#define RESERVESIZE 0
  63. X/* This array contains arbitrary screen labels */
  64. Xstruct labelinfo Lcz1[] = {
  65. X#MENU
  66. XName:                  Line:%       Mod:%        Octave   Vibrato Wave:%
  67. X                                                  %              Delay:%
  68. X                   Envelope                                       Rate:%
  69. X       w1 w2       1   2   3   4   5   6   7   8                 Depth:%
  70. XDCO1    %  %      % @ % @ % @ % @ % @ % @ % @ % @  <-Rate  S=SUS E=END
  71. X                  %   %   %   %   %   %   %   %    <-Level
  72. XDCW1  follow: %   % @ % @ % @ % @ % @ % @ % @ % @
  73. X                  %   %   %   %   %   %   %   %     Level  VA VW VP
  74. XDCA1  follow: %   % @ % @ % @ % @ % @ % @ % @ % @    %     %  %  %
  75. X                  %   %   %   %   %   %   %   %
  76. X-------------------------------------------------  Detune
  77. XDCO2    %  %      % @ % @ % @ % @ % @ % @ % @ % @  % Oct:%  Note:%  Fine: %
  78. X                  %   %   %   %   %   %   %   %
  79. XDCW2  follow: %   % @ % @ % @ % @ % @ % @ % @ % @
  80. X                  %   %   %   %   %   %   %   %     Level  VA VW VP
  81. XDCA2  follow: %   % @ % @ % @ % @ % @ % @ % @ % @    %     %  %  %
  82. X                  %   %   %   %   %   %   %   %
  83. XPortamento    Glide     Bend   Mod. Wheel        Amp.
  84. XSweep: %      Note: %     %    Depth:        %   Aftertouch: %
  85. X Time: %      Time: %          Aftertouch:   %
  86. X
  87. X   Pitch %    Vol  %
  88. X   Dur   %    Chan %
  89. X
  90. X#END
  91. X-1,-1,NULL
  92. X};
  93. X
  94. Xstruct paraminfo  Pcz1[] =  {
  95. X/*
  96. XNAME        TYPE    POS    MAX    OFFSET    MASK    SHIFT    ADHOC
  97. X */
  98. X#O line        czline    %%    3    0
  99. X#O mod        czmod    %%    2    0
  100. X#O vwave    num    %%    4    0            *5
  101. X#O oct        num    %%    1    0            *5
  102. X#O vdelay    cznum2    %%    99    0
  103. X#O vrate    cznum2    %%    99    0
  104. X#O vdepth    cznum2    %%    99    0
  105. X#O o1w1        num    %%    8    0            *5
  106. X#O o1w2        num    %%    8    0
  107. X#O 8o1r        cznum2    %%    99    0
  108. X#O 8o1f        czflag    @@    2    0
  109. X#O 8o1l        cznum2    %%    99    0
  110. X#O wf1        num    %%    9    0
  111. X#O 8w1r        cznum2    %%    99    0
  112. X#O 8w1f        czflag    @@    2    0
  113. X#O 8w1l        cznum2    %%    99    0
  114. X#O af1        num    %%    9    0
  115. X#O 8a1r        cznum2    %%    99    0
  116. X#O 8a1f        czflag    @@    2    0
  117. X#O level1    cznum2    %%    15    0            *5
  118. X#O va1        cznum2    %%    15    0
  119. X#O vw1        cznum2    %%    15    0
  120. X#O vo1        cznum2    %%    15    0
  121. X#O 8a1l        cznum2    %%    99    0
  122. X#O o2w1        num    %%    8    0            *5
  123. X#O o2w2        num    %%    8    0            *5
  124. X#O 8o2r        cznum2    %%    99    0
  125. X#O 8o2f        czflag    @@    2    0
  126. X#O detsign    czdet    %%    1    0
  127. X#O detoct    num    %%    3    0
  128. X#O detnote    cznum2    %%    11    0
  129. X#O detfine    cznum2    %%    60    0
  130. X#O 8o2l        cznum2    %%    99    0
  131. X#O wf2        num    %%    9    0
  132. X#O 8w2r        cznum2    %%    99    0
  133. X#O 8w2f        czflag    @@    2    0
  134. X#O 8w2l        cznum2    %%    99    0
  135. X#O af2        num    %%    9    0
  136. X#O 8a2r        cznum2    %%    99    0
  137. X#O 8a2f        czflag    @@    2    0
  138. X#O level2    cznum2    %%    15    0            *5
  139. X#O va2        cznum2    %%    15    0
  140. X#O vw2        cznum2    %%    15    0
  141. X#O vo2        cznum2    %%    15    0
  142. X#O 8a2l        cznum2    %%    99    0
  143. X#O psweep    cznum2    %%    1    0
  144. X#O gnote    num    %%    12    0
  145. X#O bend        cznum2    %%    12    0
  146. X#O mdepth    cznum2    %%    99    0
  147. X#O amptouch    cznum2    %%    99    0
  148. X#O ptime    cznum2    %%    99    0
  149. X#O gtime    cznum2    %%    99    0
  150. X#O mtouch    cznum2    %%    99    0
  151. X#O autopitch    num    %%    127    -60
  152. X#O autovol    num    %%    127    -63
  153. X#O autodur    num    %%    20    -5            *5
  154. X#O autochan    num    %%    16    -1            *5
  155. XNULL,NULL,-1,-1,-1,-1,visnum,0,0,0,0
  156. X};
  157. X
  158. X
  159. X/*  The following table converts AMP level visual values into
  160. X    MIDI values 00 - 5F.
  161. X */
  162. XUBYTE ampLevelMIDI[10] = {
  163. X    0x00, 0x08, 0x11, 0x1a, 0x24, 0x2f, 0x3a, 0x45, 0x52, 0x5f
  164. X    };
  165. X
  166. X/*  The following table converts WAVE key follow visual values 0-9 into
  167. X    MIDI values 00 - FF.
  168. X */
  169. XUBYTE keyFollowMIDI[10] = {
  170. X    0x00, 0x19, 0x33, 0x4e, 0x6a, 0x86, 0xa3, 0xc1, 0xdf, 0xff
  171. X    };
  172. X
  173. X/*  The following table converts a simple VIBRATO depth value (0..99)
  174. X    into a word representing bytes 1-2 of the vibrato depth group. */
  175. XUSHORT vDepthTable[100] = {
  176. X/* 00 */    0x0001, 0x0002, 0x0003, 0x0004, 0x0005,
  177. X/* 05 */    0x0006, 0x0007, 0x0008, 0x0009, 0x000a,
  178. X/* 10 */    0x000b, 0x000c, 0x000e, 0x000e, 0x000f,
  179. X/* 15 */    0x0010, 0x0011, 0x0012, 0x0013, 0x0014,
  180. X/* 20 */    0x0015, 0x0016, 0x0017, 0x0018, 0x0019,
  181. X/* 25 */    0x001a, 0x001b, 0x001c, 0x001d, 0x001e,
  182. X/* 30 */    0x001f, 0x0020, 0x0023, 0x0025, 0x0027,
  183. X/* 35 */    0x0029, 0x002b, 0x002d, 0x002f, 0x0031,
  184. X/* 40 */    0x0033, 0x0035, 0x0037, 0x0039, 0x003b,
  185. X/* 45 */    0x003d, 0x003f, 0x0041, 0x0047, 0x004b,
  186. X/* 50 */    0x004f, 0x0053, 0x0057, 0x005b, 0x005f,
  187. X/* 55 */    0x0063, 0x0067, 0x006b, 0x006f, 0x0073,
  188. X/* 60 */    0x0077, 0x007b, 0x007f, 0x0083, 0x008f,
  189. X/* 65 */    0x0097, 0x009f, 0x00a7, 0x00af, 0x00b7,
  190. X/* 70 */    0x00bf, 0x00c7, 0x00cf, 0x00d7, 0x00df,
  191. X/* 75 */    0x00e7, 0x00ef, 0x00f7, 0x00ff, 0x0107,
  192. X/* 80 */    0x011f, 0x012f, 0x013f, 0x014f, 0x015f,
  193. X/* 85 */    0x016f, 0x017f, 0x018f, 0x019f, 0x01af,
  194. X/* 90 */    0x01bf, 0x01cf, 0x01df, 0x01ef, 0x01ff,
  195. X/* 95 */    0x020f, 0x023f, 0x025f, 0x027f, 0x0300
  196. X};
  197. X
  198. X
  199. X/*  The following table converts a simple VIBRATO delay time index
  200. X    (0..99) into a word representing the second two bytes of the
  201. X    vibrato delay group.  As usual, this represents some really wierd
  202. X    encoding.
  203. X*/
  204. X
  205. XUSHORT vDelayTable[100] = {
  206. X/* 00 */    0x0000, 0x0001, 0x0002, 0x0003, 0x0004,
  207. X/* 05 */    0x0005, 0x0006, 0x0007, 0x0008, 0x0009,
  208. X/* 10 */    0x000a, 0x000b, 0x000c, 0x000d, 0x000e,
  209. X/* 15 */    0x000f, 0x0010, 0x0011, 0x0012, 0x0013,
  210. X/* 20 */    0x0014, 0x0015, 0x0016, 0x0017, 0x0018,
  211. X/* 25 */    0x0019, 0x001a, 0x001b, 0x001c, 0x001d,
  212. X/* 30 */    0x001e, 0x001f, 0x0021, 0x0023, 0x0025, /* <== change begins */
  213. X/* 35 */    0x0027, 0x0029, 0x002b, 0x002d, 0x002f,
  214. X/* 40 */    0x0031, 0x0033, 0x0035, 0x0037, 0x0039,
  215. X/* 45 */    0x003b, 0x003d, 0x003f, 0x0043, 0x0047,
  216. X/* 50 */    0x004b, 0x004f, 0x0053, 0x0057, 0x005b,
  217. X/* 55 */    0x005f, 0x0063, 0x0067, 0x006b, 0x006f,
  218. X/* 60 */    0x0073, 0x0077, 0x007b, 0x007f, 0x0087,
  219. X/* 65 */    0x008f, 0x0097, 0x009f, 0x00a7, 0x00af,
  220. X/* 70 */    0x00b7, 0x00bf, 0x00c7, 0x00d7, 0x00df,
  221. X/* 75 */    0x00e7, 0x00ef, 0x00f7, 0x00ff, 0x000f,
  222. X/* 80 */    0x010f, 0x011f, 0x012f, 0x013f, 0x014f,
  223. X/* 85 */    0x015f, 0x016f, 0x017f, 0x018f, 0x019f,
  224. X/* 90 */    0x01af, 0x01bf, 0x01cf, 0x01df, 0x01ef,
  225. X/* 95 */    0x01ff, 0x021f, 0x023f, 0x025f, 0x017f
  226. X};
  227. X
  228. X/*  The following table converts a simple VIBRATO rate index (0..99)
  229. X    into the value of bytes 1-2 of the vibrato rate group. */
  230. XUSHORT vRateTable[100] = {
  231. X/* 00 */    0x0020, 0x0040, 0x0060, 0x0080, 0x00a0,
  232. X/* 05 */    0x00c0, 0x00e0, 0x0100, 0x0120, 0x0140,
  233. X/* 10 */    0x0160, 0x0180, 0x01a0, 0x01c0, 0x01e0,
  234. X/* 15 */    0x0200, 0x0220, 0x0240, 0x0260, 0x0280,
  235. X/* 20 */    0x02a0, 0x02c0, 0x02e0, 0x0300, 0x0320,
  236. X/* 25 */    0x0340, 0x0360, 0x0380, 0x03a0, 0x03c0,
  237. X/* 30 */    0x03e0, 0x0400, 0x0460, 0x04a0, 0x04e0,
  238. X/* 35 */    0x0520, 0x0560, 0x05a0, 0x05e0, 0x0620,
  239. X/* 40 */    0x0660, 0x06a0, 0x06e0, 0x0720, 0x0760,
  240. X/* 45 */    0x07a0, 0x07e0, 0x0820, 0x08e0, 0x0960,
  241. X/* 50 */    0x09e0, 0x0a60, 0x0ae0, 0x0b60, 0x0be0,
  242. X/* 55 */    0x0c60, 0x0ce0, 0x0d60, 0x0de0, 0x0e60,
  243. X/* 60 */    0x0ee0, 0x0f60, 0x0fe0, 0x1060, 0x11e0,
  244. X/* 65 */    0x12e0, 0x13e0, 0x14e0, 0x15e0, 0x16e0,
  245. X/* 70 */    0x17e0, 0x18e0, 0x19e0, 0x1ae0, 0x1be0,
  246. X/* 75 */    0x1ce0, 0x1de0, 0x1ee0, 0x1fe0, 0x20e0,
  247. X/* 80 */    0x23e0, 0x25e0, 0x27e0, 0x29e0, 0x2be0,
  248. X/* 85 */    0x2d30, 0x2fe0, 0x31e0, 0x33e0, 0x35e0,
  249. X/* 90 */    0x37e0, 0x39e0, 0x3be0, 0x3de0, 0x3fe0,
  250. X/* 95 */    0x41e0, 0x47e0, 0x4be0, 0x4fe0, 0x53e0
  251. X};
  252. X
  253. X
  254. X
  255. X/*  FUNCTION
  256. X        cz1din - convert CZ1 data to program format.
  257. X
  258. X    SYNOPSIS
  259. X        int cz1din(data)
  260. X                struct ToneData *data;
  261. X
  262. X    DESCRIPTION
  263. X        Take info from <data> and stuff values into the P array, using
  264. X        the setval and setopval functions.
  265. X*/
  266. Xint
  267. Xcz1din(data)
  268. X    struct ToneData *data;
  269. X{
  270. X    register int     value;
  271. X
  272. X    setval("line", (INT16)data->lineAndOctave & 3);
  273. X    value = (data->waveForms1[1] >> 3) & 7;
  274. X    if (value == 4)
  275. X        value = RING;
  276. X    else if (value == 3)
  277. X        value = NOISE;
  278. X    setval("mod", (INT16)value);
  279. X    value = (data->lineAndOctave >> 2) & 3;
  280. X    if (value == 2) value = -1;     /* 2 => -1 */
  281. X    setval("oct", (INT16)value);
  282. X
  283. X    /* Extract the DETUNE information: */
  284. X    setval("detsign", (INT16)data->detuneSign);
  285. X
  286. X    /* The FINE detune info must have a correction factor applied: */
  287. X    value = data->detuneFine >> 2;
  288. X    if (value > 47) value -= 3;
  289. X    else if (value > 31) value -= 2;
  290. X    else if (value > 15) value -= 1;
  291. X    setval("detfine", (INT16)value);
  292. X
  293. X    /* The NOTE and OCTAVE detune info are obtained by factoring the
  294. X       semitone info in detuneCoarse: */
  295. X
  296. X    setval("detnote", (INT16)data->detuneCoarse % 12);
  297. X    setval("detoct", (INT16)data->detuneCoarse / 12);
  298. X
  299. X    /* Get the VIBRATO info: */
  300. X    value = data->vibratoWave & 0x2E;
  301. X    switch (value) {
  302. X    case 2:
  303. X        value = 4;
  304. X        break;
  305. X    case 4:
  306. X        value = 2;
  307. X        break;
  308. X    case 8:
  309. X        value = 1;
  310. X        break;
  311. X
  312. X    case 32:
  313. X        value = 3;
  314. X        break;
  315. X
  316. X    default:
  317. X        value = 1;
  318. X        break;
  319. X
  320. X    }
  321. X    setval("vwave",     (INT16)value);
  322. X    setval("vdelay",    (INT16)data->vibratoTime[0]);
  323. X    setval("vrate",     (INT16)data->vibratoRate[0]);
  324. X    setval("vdepth",    (INT16)data->vibratoDepth[0]);
  325. X
  326. X    /* Set onscreen parameters for patch area 1. */
  327. X    setwaveforms("o1", data->waveForms1);
  328. X
  329. X    /* setenvelope sets all rates and levels for an envelope. */
  330. X    setenvelope("o1", data->DCO_Envelope1, data->DCO_EndStep1);
  331. X    setenvelope("w1", data->DCW_Envelope1, data->DCW_EndStep1);
  332. X    setenvelope("a1", data->DCA_Envelope1, data->DCA_EndStep1);
  333. X
  334. X    /* Set key follow parameters for area 1. */
  335. X
  336. X    setval("wf1", (INT16)data->DCW1_KeyFollow[0] & 0xf);
  337. X    setval("af1", (INT16)data->DCA1_KeyFollow[0] & 0xf);
  338. X
  339. X    value = 15 - (data->DCA1_KeyFollow[0] >> 4);
  340. X    setval("level1", (INT16)value);
  341. X
  342. X    /* Set onscreen parameters for patch area 2. */
  343. X    setwaveforms("o2", data->waveForms2);
  344. X
  345. X    /* Set the envelope parameters for patch area 2. */
  346. X    setenvelope("o2", data->DCO_Envelope2, data->DCO_EndStep2);
  347. X    setenvelope("w2", data->DCW_Envelope2, data->DCW_EndStep2);
  348. X    setenvelope("a2", data->DCA_Envelope2, data->DCA_EndStep2);
  349. X
  350. X    /* Set key follow parameters for area 2. */
  351. X
  352. X    setval("wf2", (INT16)data->DCW2_KeyFollow[0] & 0xf);
  353. X    setval("af2", (INT16)data->DCA2_KeyFollow[0] & 0xf);
  354. X
  355. X    value = 15 - (data->DCA2_KeyFollow[0] >> 4);
  356. X    setval("level2", (INT16)value);
  357. X    return 0;
  358. X}
  359. X
  360. X/*  FUNCTION
  361. X        cz1dout - convert program data to CZ1 format.
  362. X
  363. X    SYNOPSIS
  364. X        int cz1dout(data)
  365. X                struct ToneData *data;
  366. X
  367. X    DESCRIPTION
  368. X        Cz1dout takes data from the P array and converts it to CZ1 format,
  369. X        storing it in the patch area defined by <data>.
  370. X
  371. X*/
  372. Xint
  373. Xcz1dout(data)
  374. X    struct ToneData *data;
  375. X{
  376. X    int value, value2;
  377. X
  378. X    value = getval("oct");          /* Get, correct octave value. */
  379. X    if (value < 0) value = 2;
  380. X    data->lineAndOctave = getval("line") | (value << 2);
  381. X    data->detuneSign = getval("detsign");
  382. X    /* The DETUNE coarse data is converted from OCT and NOTE into a
  383. X       semitone value ranging from 0 to 47(2F).  It is then stored
  384. X       in the high byte of the pair.
  385. X    */
  386. X    value = getval("detoct") * 12 + getval("detnote");
  387. X    data->detuneCoarse = value;
  388. X
  389. X    /* The DETUNE fine data has a correction factor applied to it,
  390. X       and is then shifted to fit into bits 7-2 of the the low byte.
  391. X    */
  392. X    value = getval("detfine");
  393. X    if (value > 45) value += 3;
  394. X    else if (value > 30) value += 2;
  395. X    else if (value > 15) value += 1;
  396. X    data->detuneFine = value << 2;
  397. X
  398. X    value = getval("detnote");
  399. X    value += getval("detoct") * 12;
  400. X    data->detuneCoarse = value;
  401. X
  402. X    /* VIBRATO information: */
  403. X    value = getval("vwave");
  404. X    switch (value) {
  405. X    case 1:
  406. X        value = 8;
  407. X        break;
  408. X    case 2:
  409. X        value = 4;
  410. X        break;
  411. X    case 3:
  412. X        value = 32;
  413. X        break;
  414. X    default:
  415. X        break;
  416. X    }
  417. X    data->vibratoWave = data->vibratoWave = value;
  418. X
  419. X    /* Get vibrato delay. */
  420. X    value = getval("vdelay");
  421. X    data->vibratoTime[0] = value;
  422. X    value = vDelayTable[value];
  423. X    data->vibratoTime[1] = value;
  424. X    data->vibratoTime[2] = value>>8;
  425. X
  426. X    /* Get vibrato rate. */
  427. X    value = getval("vrate");
  428. X    data->vibratoRate[0] = value;
  429. X    value = vRateTable[value];
  430. X    data->vibratoRate[1] = value;
  431. X    data->vibratoRate[2] = value >> 8 ;
  432. X
  433. X    /* Get vibrato depth. */
  434. X    value = getval("vdepth");
  435. X    data->vibratoDepth[0] = value;
  436. X    value = vDepthTable[value];     /* Get bytes 1, 2 from table. */
  437. X    data->vibratoDepth[1] = value;
  438. X    data->vibratoDepth[2] = value >> 8;
  439. X
  440. X    /* Get envelope values: */
  441. X    getenvelope("o1", data->DCO_Envelope1, &data->DCO_EndStep1);
  442. X    getenvelope("w1", data->DCW_Envelope1, &data->DCW_EndStep1);
  443. X    getenvelope("a1", data->DCA_Envelope1, &data->DCA_EndStep1);
  444. X    getwaveforms("o1", data->waveForms1);
  445. X    value = getval("wf1");
  446. X    data->DCW1_KeyFollow[0] = value;
  447. X    data->DCW1_KeyFollow[1] = keyFollowMIDI[value];
  448. X
  449. X    /* The amp level and key follow values share the DCAx_KeyFollow
  450. X       field.                                                       */
  451. X
  452. X    value = getval("af1");
  453. X    value2 = getval("level1");
  454. X    value2 = (15 - value2) << 4;
  455. X    data->DCA1_KeyFollow[0] = value | value2;
  456. X    data->DCA1_KeyFollow[1] = ampLevelMIDI[value];
  457. X
  458. X    getenvelope("o2", data->DCO_Envelope2, &data->DCO_EndStep2);
  459. X    getenvelope("w2", data->DCW_Envelope2, &data->DCW_EndStep2);
  460. X    getenvelope("a2", data->DCA_Envelope2, &data->DCA_EndStep2);
  461. X    getwaveforms("o2", data->waveForms2);
  462. X    data->DCW2_KeyFollow[0] = value = getval("wf2");
  463. X    data->DCW2_KeyFollow[1] = keyFollowMIDI[value];
  464. X
  465. X    value = getval("af2");
  466. X    value2 = getval("level2");
  467. X    value2 = (15 - value2) << 4;
  468. X    data->DCA2_KeyFollow[0] = value | value2;
  469. X    data->DCA2_KeyFollow[1] = ampLevelMIDI[value];
  470. X
  471. X    return 0;
  472. X}
  473. X
  474. X/*  FUNCTION
  475. X        cz1nof - return a pointer to a patch internal name.
  476. X
  477. X    SYNOPSIS
  478. X        char *cz1nof(data)
  479. X              struct ToneData *data;
  480. X
  481. X    DESCRIPTION
  482. X        Cz1nof extracts a local copy of the voice name (in <data>) and
  483. X        returns a pointer to it.
  484. X
  485. X*/
  486. X
  487. Xchar *
  488. Xcz1nof(data)
  489. X    struct ToneData *data;
  490. X{
  491. X    static char name[17];
  492. X    UBYTE *n;
  493. X    int i;
  494. X
  495. X    for (i=0, n = data->name; i < 16; ++i)
  496. X        name[i] = *n++;
  497. X
  498. X    name[16] = '\0';
  499. X    return name;
  500. X}
  501. X
  502. X/*  FUNCTION
  503. X        cz1snof - store a voice name.
  504. X
  505. X    SYNOPSIS
  506. X        int cz1snof(data, name)
  507. X                struct ToneData *data, *name;
  508. X
  509. X    DESCRIPTION
  510. X        Cz1snof stores the new voice <name> into the patch area defined
  511. X        by <data>.
  512. X
  513. X*/
  514. Xint
  515. Xcz1snof(data, name)
  516. X    struct ToneData *data; char *name;
  517. X
  518. X{
  519. X    int     i;
  520. X    UBYTE   *n;
  521. X
  522. X    for (i = 0, n = data->name; (i < 16) && *name; ++i)
  523. X        *n++ = *name++;
  524. X
  525. X    while (i < 16) {
  526. X        *n++ = ' ';
  527. X        ++i;
  528. X    }
  529. X}
  530. X
  531. X#ifdef CZ1SBULK
  532. X/*  FUNCTION
  533. X        cz1sbulk - send bulk patch data to the CZ1.
  534. X
  535. X    SYNOPSIS
  536. X        int cz1sbulk(data)
  537. X                struct ToneData *data;
  538. X
  539. X    DESCRIPTION
  540. X        Cz1sbulk sends 64 voice patches to the CZ1.
  541. X
  542. X*/
  543. X
  544. Xint
  545. Xcz1sbulk(data)
  546. X    struct ToneData *data;
  547. X{
  548. X    return 0;
  549. X}
  550. X#endif
  551. X
  552. X/*  FUNCTION
  553. X        cz1gbulk - get bulk patch data from CZ1.
  554. X
  555. X    SYNOPSIS
  556. X        int cz1gbulk(data)
  557. X                char *data;
  558. X
  559. X    DESCRIPTION
  560. X        Cz1gbulk reads 64 voices of patch data from the CZ1 into <data>.
  561. X
  562. X*/
  563. Xint
  564. Xcz1gbulk(data)
  565. X    char *data;
  566. X{
  567. X    char    *addr;
  568. X    int     i;
  569. X    char    msg[40];
  570. X    int     result, voice;
  571. X
  572. X    /* !!! I want to change this so we can access the cartridge pack
  573. X     * !!! as well.  A simple flag should do it.
  574. X     */
  575. X
  576. X    for (voice = FIRST_INTERNAL; voice <= LAST_INTERNAL; ++voice) {
  577. X        addr = data + voice * sizeof(struct ToneData);
  578. X        (void)sprintf(msg, "Reading CZ1 voice %d.", voice);
  579. X        windgoto(3,10);
  580. X        windstr(msg);
  581. X        windrefresh();
  582. X        if (result = ReceiveCZPatch((struct ToneData *)addr,
  583. X                    (UBYTE)Channel, (UBYTE)voice)) {
  584. X            (void)sprintf(msg, "Failed to read CZ1 voice %d!", voice);
  585. X            windgoto(3, 10);
  586. X            windstr(msg);
  587. X            windrefresh();
  588. X            return result;
  589. X        }
  590. X    }
  591. X    for (i = 0; i < 39; ++i) msg[i] = ' ';
  592. X    msg[i] = '\0';
  593. X    windgoto(3, 10);
  594. X    windstr(msg);
  595. X    windrefresh();
  596. X    return 0;
  597. X}
  598. X
  599. X/*  FUNCTION
  600. X        cz1sedit - send a single voice to the CZ1 edit buffer.
  601. X
  602. X    SYNOPSIS
  603. X        int cz1sedit(data)
  604. X                struct ToneData *data;
  605. X
  606. X    DESCRIPTION
  607. X        Cz1sedit sends a single voice to the CZ1 edit buffer.
  608. X
  609. X*/
  610. X
  611. Xint
  612. Xcz1sedit(data)
  613. X    struct ToneData *data;
  614. X{
  615. X    return SendCZPatch(data, Channel, SOUND_DATA);
  616. X}
  617. X
  618. X/*  FUNCTION
  619. X        cz1sone - send one voice to the CZ1.
  620. X
  621. X    SYNOPSIS
  622. X        int cz1sone(vx, data)
  623. X                    int             vx;
  624. X                    struct ToneData *data;
  625. X
  626. X    DESCRIPTION
  627. X        Cz1sone sends one voice (number specified by <vx>) to the CZ1.
  628. X        The <data> argument points to the patch data to be sent.
  629. X
  630. X        Cz1sone returns 0 on success, -1 on failure.
  631. X
  632. X*/
  633. X
  634. Xint
  635. Xcz1sone(vx, data)
  636. X    int     vx;
  637. X    char    *data;
  638. X{
  639. X    return SendCZPatch((struct ToneData *)data, Channel, vx);
  640. X}
  641. X
  642. X/*  FUNCTION
  643. X        GetCZSysEx - wait for system exclusive byte or time-out.
  644. X
  645. X    SYNOPSIS
  646. X        int GetCZEndSysEx();
  647. X
  648. X    DESCRIPTION
  649. X        GetCZSysEx waits for a system exclusive byte from the CZ1.
  650. X        If the next byte received is a system exclusive, a zero
  651. X        result is returned, indicating success.  If the byte received
  652. X        is not a sysex, or if a timeout occurs, a one (1) is returned
  653. X        and the error reason, Reason, is set appropriately.
  654. X
  655. X*/
  656. Xint
  657. XGetCZEndSysEx()
  658. X{
  659. X    unsigned char    c;
  660. X    long    begin, toolong;
  661. X    static char    msg[40];
  662. X
  663. X    begin = milliclock();
  664. X    toolong = begin + 2000;     /* Wait for 2 seconds. */
  665. X
  666. X    while (milliclock() < toolong) {
  667. X        if (STATMIDI) {
  668. X            c = getmidi() & 0xFF;
  669. X            if (c != END_SYSTEM_EXCLUSIVE) {
  670. X                (void)sprintf(msg,"Waited for %02xx, got %02xx",
  671. X                        END_SYSTEM_EXCLUSIVE, c & 0xFF);
  672. X                Reason = msg;
  673. X                return 1;
  674. X            }
  675. X            return 0;
  676. X        }
  677. X    }
  678. X    Reason = "Timed out waiting for end sysex.";
  679. X    return 1;
  680. X}
  681. X
  682. X/*  FUNCTION
  683. X        SendCZPatch - send one voice to the CZ1
  684. X
  685. X    SYNOPSIS
  686. X        int SendCZPatch(tonedata, channel, voice)
  687. X                        struct ToneData *tonedata;
  688. X                        int channel, voice;
  689. X
  690. X    DESCRIPTION
  691. X        SendCzPatch sends one voice patch (<tonedata>) to the CZ1,
  692. X        using the specified <channel>.  The <voice> argument determines
  693. X        which synthesizer program area the data will be sent to.
  694. X
  695. X        Note that the CZ family behaves in a wierd way, splitting all
  696. X        tone data bytes into two pieces.  SendToneData splits the bytes
  697. X        to a local buffer prior to transmitting them.
  698. X*/
  699. Xstatic int
  700. XSendCZPatch(tonedata, channel, voice)
  701. Xstruct ToneData *tonedata;
  702. Xint channel,voice;
  703. X{
  704. X    long    begin, toolong;             /* timer values */
  705. X
  706. X#ifdef CZ101
  707. X/* Receive request 1 system exclusive */
  708. X
  709. Xstatic UBYTE receive_request[] = {
  710. X    0xF0,0x44,0x00,0x00,0x70,0x20,0x00 };
  711. X#endif
  712. X
  713. X#ifdef CZ1
  714. Xstatic UBYTE receive_request[] = {
  715. X        0xF0,0x44,0x00,0x00,0x70,0x21,0x00 };
  716. X#endif
  717. X
  718. X    UBYTE data[512];
  719. X    UBYTE *ptr;
  720. X
  721. X    int i;
  722. X
  723. X    /* Clear the serial buffer of any unread data */
  724. X  if (!synthoutfileflag)
  725. X    flushmidi();
  726. X
  727. X    /* Fill in channel and voice, then send request. */
  728. X
  729. X    receive_request [4] = 0x70 | ((channel - 1) & 0x0F);
  730. X    receive_request [6] = voice;
  731. X
  732. X    sendmulti(receive_request, sizeof(receive_request));
  733. X
  734. X    /* Get the reply message. It's six bytes consisting of:
  735. X            F0 44 00 00 7N 30  where N is the channel number.
  736. X     */
  737. X
  738. X    begin = milliclock();
  739. X    toolong = begin + 5000L;
  740. X  if (!synthoutfileflag)
  741. X    for (i = 0; i < 6; ) {
  742. X        if (STATMIDI) {                 /* Something available? */
  743. X            data[i++] = getmidi();
  744. X        }
  745. X        else if (milliclock() > toolong) {
  746. X            Reason = "Timeout waiting for receive request 1 reply.";
  747. X            return 1;
  748. X        }
  749. X    }
  750. X
  751. X    /* Split the data into 4-bit nybbles. */
  752. X
  753. X    ptr = (UBYTE *) tonedata;
  754. X
  755. X    for (i=0; i<sizeof(struct ToneData)*2; i+=2) {
  756. X        data[i] = *ptr & 0x0F;
  757. X        data[i+1] = (*ptr >> 4) & 0x0F;
  758. X        ++ptr;
  759. X    }
  760. X
  761. X    /* Add "end-system-exclusive" to tone data buffer */
  762. X
  763. X    data[i] = END_SYSTEM_EXCLUSIVE;
  764. X
  765. X    /* Send tone data to synth */
  766. X
  767. X    sendmulti(data, sizeof(struct ToneData) * 2 + 1);
  768. X
  769. X    /* Read "end-system-exclusive" from synth */
  770. X
  771. X  if (!synthoutfileflag)
  772. X    return GetCZEndSysEx();
  773. X  else return 0;
  774. X}
  775. X
  776. X/*  FUNCTION
  777. X        ReceiveCZPatch - receive one CZ1 voice patch.
  778. X
  779. X    SYNOPSIS
  780. X        int ReceiveCZPatch(tonedata, channel, voice);
  781. X                           struct ToneData *tonedata;
  782. X                           int channel, voice;
  783. X
  784. X    DESCRIPTION
  785. X        ReceiveCZPatch requests one CZ1 voice patch. It combines the
  786. X        voice nybbles sent by the CZ1 into a normal ToneData structure.
  787. X
  788. X        ReceiveCZPatch returns zero on success.  On failure, it returns
  789. X        one (1) after setting Reason to a string describing the failure.
  790. X*/
  791. X
  792. Xint
  793. XReceiveCZPatch(tonedata, channel, voice)
  794. Xstruct ToneData *tonedata;
  795. XUBYTE channel,voice;
  796. X{
  797. X#ifdef CZ101
  798. X/* Send Request 1 system exclusive data */
  799. X
  800. Xstatic UBYTE send_request_1A [] = {
  801. X    0xF0,0x44,0x00,0x00,0x70,0x10,0x00 };
  802. X
  803. Xstatic UBYTE send_request_1B [] = {
  804. X    0x70,0x31 };
  805. X#endif
  806. X
  807. X#ifdef CZ1
  808. Xstatic UBYTE send_request_1A [] = {
  809. X        0xF0,0x44,0x00,0x00,0x70,0x11,0x00 };
  810. X
  811. Xstatic UBYTE send_request_1B [] = {
  812. X        0x70,0x31 };
  813. X#endif
  814. X
  815. X    long    begin, toolong;
  816. X    UBYTE   data[512];
  817. X    UBYTE   *ptr;
  818. X
  819. X    int i;
  820. X
  821. X    /* Clear the serial buffer of any unread data */
  822. X
  823. X    flushmidi();
  824. X
  825. X    /* Set channel and voice info, then send the request to the CZ1. */
  826. X
  827. X    send_request_1A [4] = 0x70 | ((channel - 1) & 0x0F);
  828. X    send_request_1A [6] = voice;
  829. X
  830. X    sendmulti(send_request_1A, sizeof(send_request_1A));
  831. X
  832. X    /* Get the reply message. It's six bytes consisting of:
  833. X            F0 44 00 00 7N 30  where N is the channel number.
  834. X     */
  835. X
  836. X    begin = milliclock();
  837. X    toolong = begin + 5000L;
  838. X    for (i = 0; i < 6; ) {
  839. X        if (STATMIDI) {                 /* Something available? */
  840. X            data[i++] = getmidi();
  841. X        }
  842. X        else if (milliclock() > toolong) {
  843. X            Reason = "Timeout waiting for send request 1 reply.";
  844. X            return 1;
  845. X        }
  846. X    }
  847. X    /* if from file, one more byte of header to read -- gl */
  848. X    if (synthinfileflag) (void)getmidi();
  849. X
  850. X    /* Send secondary request */
  851. X
  852. X    send_request_1B [0] = 0x70 | ((channel - 1) & 0x0F);
  853. X    sendmulti(send_request_1B, sizeof(send_request_1B));
  854. X
  855. X    /* Read tone data and "end-system-exclusive" from synth */
  856. X
  857. X    begin = milliclock();
  858. X    toolong = begin + TIMEOUT*1000;
  859. X    for (i = 0; i < (sizeof(struct ToneData) * 2) + 1; ) {
  860. X        if (STATMIDI) {
  861. X            data[i++] = getmidi();
  862. X        }
  863. X        else if (milliclock() > toolong) {
  864. X            Reason = "Timed out waiting for patch data.";
  865. X            return 1;
  866. X        }
  867. X    }
  868. X
  869. X    /* Pack the 4-bit nybbles into a ToneData structure. */
  870. X
  871. X    ptr = (UBYTE *) tonedata;
  872. X
  873. X    for (i=0; i<sizeof(struct ToneData)*2; i+=2)
  874. X        *(ptr++) = (data[i] | (data[i+1] << 4));
  875. X
  876. X    /* Echo "end-system-exclusive" */
  877. X
  878. X    sendmidi(END_SYSTEM_EXCLUSIVE);
  879. X    return 0;
  880. X}
  881. X
  882. X
  883. X/*******************************
  884. X * Screen Formatting Functions *
  885. X *******************************/
  886. X
  887. Xchar *
  888. Xvisczdet(v)
  889. X{
  890. X    if (v == 0 || v == 1) return (v ? "-" : "+");
  891. X    else return("*");
  892. X}
  893. X
  894. Xchar *
  895. Xvisczflag(v)
  896. X    int v;
  897. X{
  898. X    static char *flags[3] = {" ", "S", "E"};
  899. X
  900. X    if (v >= 0 && v < 3) return flags[v];
  901. X    else return("*");
  902. X}
  903. X
  904. Xchar *
  905. Xvisczline(v)
  906. X    int v;
  907. X{
  908. X    static char *modes[4] = {"1", "2", "1+1'", "1+2'"};
  909. X
  910. X    return modes[v & 3];
  911. X}
  912. X
  913. Xchar *
  914. Xvisczmod(v)
  915. X    int v;
  916. X{
  917. X    static char *modValues[] = { "Off", "Ring", "Noise" };
  918. X
  919. X    if (v > 2) v = 0;
  920. X    if (v >= 0) return modValues[v];
  921. X    else return("*");
  922. X}
  923. X
  924. Xchar *
  925. Xviscznum2(v)
  926. X{
  927. X    static char num[4];
  928. X
  929. X    if (v >= 0 && v < 100) {
  930. X    (void)sprintf(num,"%02d",v);
  931. X    return num;
  932. X    }
  933. X    return("*");
  934. X}
  935. X
  936. X/* not used
  937. Xchar *
  938. Xvisczoct(v)
  939. X    int v;
  940. X{
  941. X    static char *octaves[3] = {"0", "+1", "-1"};
  942. X
  943. X    if (v >= 0 && v < 3) return octaves[v];
  944. X    else return("*");
  945. X}
  946. X*/
  947. X
  948. X/*  FUNCTION
  949. X        getenvelope - get rate, level pairs for one envelope
  950. X
  951. X    SYNOPSIS
  952. X        static void getenvelope(prefix, envelope, endStep)
  953. X                                char    *prefix;
  954. X                                UBYTE   *envelope;
  955. X                                UBYTE   *endStep;
  956. X
  957. X    DESCRIPTION
  958. X        getenvelope() retrieves data values from the P array and stuffs
  959. X        them back into the synthesizer patch record.  The <prefix>
  960. X        argument describes the envelope being retrieved, while the
  961. X        <envelope> argument is a pointer to the envelope data.  <endStep>
  962. X        points to the appropriate end-of-step byte.
  963. X*/
  964. Xstatic void
  965. Xgetenvelope(prefix, envelope, endStep)
  966. X    char    *prefix;
  967. X    UBYTE   *envelope;
  968. X    UBYTE   *endStep;
  969. X{
  970. X    int     prevLevel = 0;
  971. X    UBYTE   sign;
  972. X    int     step, sx;
  973. X    int     flag, level, rate;
  974. X    char    varName[32];
  975. X    UBYTE   velocity;
  976. X
  977. X    for (step = 0, sx = 0; step < 8; ++step, sx += 2) {
  978. X        /* Retrieve RATE value: */
  979. X        (void)sprintf(varName, "%sr%d", prefix, step + 1);
  980. X        rate = getval(varName);
  981. X
  982. X        /* Now, get LEVEL value: */
  983. X        (void)sprintf(varName,"%sl%d", prefix, step+1);
  984. X        level = getval(varName);
  985. X
  986. X        /* Get flag (SUS/END): */
  987. X        (void)sprintf(varName, "%sf%d", prefix, step+1);
  988. X        flag = getval(varName);
  989. X
  990. X        /* The next statement depends upon the velocity parameters
  991. X           being named "vo1", "vw1", "va1", etc. */
  992. X
  993. X        (void)sprintf(varName, "v%s", prefix);
  994. X        velocity = getval(varName);
  995. X
  996. X        /* Convert rate,level to MIDI value: */
  997. X        switch (*prefix) {
  998. X        case 'o':
  999. X            if (rate == 99)
  1000. X                rate = 127;
  1001. X            else if (rate != 0)
  1002. X                rate = (127 * rate) / 99;
  1003. X
  1004. X            if (level > 63) level += 4;
  1005. X            break;
  1006. X        case 'w':
  1007. X            rate = (119 * rate) / 99 + 8;
  1008. X            level = (127 * level) / 99;
  1009. X            break;
  1010. X        case 'a':
  1011. X            rate = (119 * rate) / 99;
  1012. X            if (level) level += 28;
  1013. X            break;
  1014. X        default:
  1015. X            rate = 127;
  1016. X            level = 0;
  1017. X            break;
  1018. X        }
  1019. X
  1020. X        /* For RATE bytes, if the current level is less than the
  1021. X           previous level, set the sign bit: */
  1022. X        sign = (level < prevLevel ? 0x80 : 0);
  1023. X        envelope[sx] = rate | sign;
  1024. X
  1025. X        /* If this is step 7 and the flag does not indicate the end
  1026. X           step, we must force the end step now: */
  1027. X
  1028. X        if ((step == 7) && flag != 2) {
  1029. X            Redraw = 1;
  1030. X            flag = 2;
  1031. X            (void)sprintf(varName,"%sf8",prefix);
  1032. X            setval(varName, (INT16)flag);
  1033. X        }
  1034. X        if (flag == 2)  {                /* Is this the end step? */
  1035. X            level = 0;
  1036. X            *endStep = step | (velocity << 4);
  1037. X            break;
  1038. X        }
  1039. X
  1040. X        /* For LEVEL bytes, set the sign bit if the current step is
  1041. X           a SUSTAIN step: */
  1042. X
  1043. X        sign = (flag == 1 ? 0x80 : 0);
  1044. X        envelope[sx+1] = level | sign;
  1045. X        prevLevel = level;
  1046. X        if (flag == 2) break;
  1047. X    }
  1048. X
  1049. X}
  1050. X
  1051. X/*  FUNCTION
  1052. X        getwaveforms - stuff waveform info into patch area.
  1053. X
  1054. X    SYNOPSIS
  1055. X        static void getwaveforms(prefix, waveForms)
  1056. X                char    *prefix;
  1057. X                UBYTE   *waveForms;
  1058. X
  1059. X    DESCRIPTION
  1060. X        getwaveforms() converts the local representation of the
  1061. X        waveform data into the CZ1 representation. The <prefix>
  1062. X        argument determines if the waveforms to be converted are
  1063. X        for DCO1 (prefix = "o1") or DCO2 (prefix = "o2").
  1064. X*/
  1065. X
  1066. Xstatic void
  1067. Xgetwaveforms(prefix, waveForms)
  1068. X    char *prefix; UBYTE *waveForms;
  1069. X{
  1070. X    USHORT      modulation;
  1071. X    USHORT      second, waveWord, w1, w2;
  1072. X    char        varName[32];
  1073. X
  1074. X    (void)sprintf(varName,"%sw1", prefix);
  1075. X    w1 = getval(varName);
  1076. X    if (w1) --w1;               /* Do "normalization" */
  1077. X    (void)sprintf(varName,"%sw2", prefix);
  1078. X    w2 = getval(varName);
  1079. X    if (w2) {
  1080. X        --w2;
  1081. X        second = 0x200;         /* Indicate second waveform present. */
  1082. X    }
  1083. X    else
  1084. X        second = 0;
  1085. X
  1086. X    modulation = getval("mod");
  1087. X    if (modulation == RING)
  1088. X        modulation = 0x20;
  1089. X    else if (modulation == NOISE)
  1090. X        modulation = 0x18;
  1091. X
  1092. X    /* Save bits 8-6 (resonance?) of the old waveForms word. */
  1093. X    waveWord = ((waveForms[0] << 8) | waveForms[1]) & 0x1c0;
  1094. X    waveWord |= modulation;
  1095. X
  1096. X    /* Perform an inclusive OR with the new waveform components. */
  1097. X    waveWord |= ((w1<<13) | (w2<<10) | second);
  1098. X    waveForms[1] = waveWord;
  1099. X    waveForms[0] = waveWord >> 8;
  1100. X}
  1101. X
  1102. X/*  FUNCTION
  1103. X        setenvelope - set rate, level pairs for one envelope.
  1104. X
  1105. X    SYNOPSIS
  1106. X        static void setenvelope(prefix, envelope, endStep)
  1107. X                                char    *prefix;
  1108. X                                UBYTE   *envelope;
  1109. X                                UBYTE   endStep;
  1110. X
  1111. X    DESCRIPTION
  1112. X        setenvelope stuffs the P array with the <envelope> values.  It
  1113. X        uses the <prefix> string to compute the variable names that
  1114. X        are to be set.  Typical values for the <prefix> string are:
  1115. X
  1116. X            "o1"    - DCO1
  1117. X            "w1"    - DCW1
  1118. X            "a2"    - DCA2
  1119. X
  1120. X        Of course, they must match the names used in the P array.
  1121. X*/
  1122. Xstatic void
  1123. Xsetenvelope(prefix, envelope, endStep)
  1124. X            char *prefix; UBYTE *envelope; UBYTE endStep;
  1125. X{
  1126. X    int     step, sx, value;
  1127. X    char    varName[32];
  1128. X
  1129. X    for (step = 0, sx = 0; step < 8; ++step, sx += 2) {
  1130. X        (void)sprintf(varName, "%sr%d", prefix, step + 1);
  1131. X        value = envelope[sx] & 0x7f;
  1132. X        /* Perform rate value conversion, based on envelope name: */
  1133. X        switch (*prefix) {
  1134. X        case 'o':
  1135. X            if (value == 127)
  1136. X                value = 99;
  1137. X            else if (value != 0)
  1138. X                value = (value * 99) / 127 + 1;
  1139. X            break;
  1140. X        case 'w':
  1141. X            value -= 8;         /* Nice stuff! :-( */
  1142. X            if (value == 0x77)
  1143. X                value = 99;
  1144. X            else if (value != 0)
  1145. X                value = (value * 99) / 119 + 1;
  1146. X            break;
  1147. X        case 'a':
  1148. X            if (value == 0x77)
  1149. X                value = 99;
  1150. X            else if (value != 0)
  1151. X                value = (99 * value) / 119 + 1;
  1152. X            break;
  1153. X        default:
  1154. X            break;
  1155. X        }
  1156. X        setval(varName, (INT16)value);
  1157. X
  1158. X        (void)sprintf(varName, "%sl%d", prefix, step + 1);
  1159. X        value = envelope[sx+1] & 0x7f;
  1160. X        /* Perform nasty conversion on level value: */
  1161. X        switch (*prefix) {
  1162. X        case 'o':
  1163. X            if (value > 63) value -= 4; /* Sure! Why not? Grrr... */
  1164. X            break;
  1165. X        case 'w':
  1166. X            if (value == 0x7f)
  1167. X                value = 99;
  1168. X            else if (value != 0)
  1169. X                value = (value * 99) / 127 + 1;
  1170. X            break;
  1171. X        case 'a':
  1172. X            if (value) value -= 28;     /* Makes sense to me! Phht! */
  1173. X            break;
  1174. X        default:
  1175. X            break;
  1176. X        }
  1177. X        setval(varName, (INT16)value);
  1178. X
  1179. X        /* Set SUS/END flag. */
  1180. X        (void)sprintf(varName, "%sf%d", prefix, step+1);
  1181. X        if ((endStep & 7) == step)
  1182. X            value = 2;
  1183. X        else if (envelope[sx+1] & 0x80)
  1184. X            value = 1;
  1185. X        else
  1186. X            value = 0;
  1187. X        setval(varName, (INT16)value);
  1188. X
  1189. X        /* Get VELOCITY parameter. */
  1190. X        (void)sprintf(varName, "v%s", prefix);
  1191. X        setval( varName, (INT16)endStep >> 4 );
  1192. X    }
  1193. X}
  1194. X
  1195. X/*  FUNCTION
  1196. X        setwaveforms - extract waveform data from patch area.
  1197. X
  1198. X    SYNOPSIS
  1199. X        static void setwaveforms(prefix, waveForms)
  1200. X                        char    *prefix;
  1201. X                        UBYTE   *waveForms;
  1202. X
  1203. X    DESCRIPTION
  1204. X        setwaveforms extracts the waveform data from a CZ1 patch
  1205. X        and converts it to the on-screen representation.
  1206. X
  1207. X*/
  1208. Xstatic void
  1209. Xsetwaveforms(prefix, waveForms)
  1210. X    char *prefix; UBYTE *waveForms;
  1211. X{
  1212. X    char    varName[33];
  1213. X    USHORT  waveWord;
  1214. X    USHORT  w1, w2;
  1215. X
  1216. X    waveWord = waveForms[0] << 8 | waveForms[1];
  1217. X    w1 = ((waveWord >> 13) & 7) + 1;
  1218. X    w2 = ((waveWord >> 10) & 7);
  1219. X    if (waveWord & 0x200)           /* Second waveform is present? */
  1220. X        w2 += 1;
  1221. X    else
  1222. X        w2 = 0;
  1223. X    (void)sprintf(varName,"%sw1", prefix);
  1224. X    setval(varName, (INT16)w1);
  1225. X    (void)sprintf(varName,"%sw2", prefix);
  1226. X    setval(varName, (INT16)w2);
  1227. X}
  1228. X
  1229. X
  1230. X#ifndef AMIGA
  1231. X/*  FUNCTION
  1232. X        sendmulti - send multiple bytes to midi device
  1233. X
  1234. X    SYNOPSIS
  1235. X        void sendmulti(buffer, count)
  1236. X                char    *buffer;
  1237. X                int     count;
  1238. X
  1239. X    DESCRIPTION
  1240. X        sendmulti transfers <count> bytes from <buffer> to the currently
  1241. X        open midi device.
  1242. X
  1243. X*/
  1244. X
  1245. Xvoid
  1246. Xsendmulti(buffer, count)
  1247. X    UBYTE *buffer; int count;
  1248. X{
  1249. X    while (count--) sendmidi((int)*buffer++);
  1250. X}
  1251. X#endif
  1252. X
  1253. END_OF_FILE
  1254. if test 33418 -ne `wc -c <'cz1.mnu'`; then
  1255.     echo shar: \"'cz1.mnu'\" unpacked with wrong size!
  1256. fi
  1257. # end of 'cz1.mnu'
  1258. fi
  1259. echo shar: End of archive 12 \(of 15\).
  1260. cp /dev/null ark12isdone
  1261. MISSING=""
  1262. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ; do
  1263.     if test ! -f ark${I}isdone ; then
  1264.     MISSING="${MISSING} ${I}"
  1265.     fi
  1266. done
  1267. if test "${MISSING}" = "" ; then
  1268.     echo You have unpacked all 15 archives.
  1269.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1270. else
  1271.     echo You still need to unpack the following archives:
  1272.     echo "        " ${MISSING}
  1273. fi
  1274. ##  End of shell archive.
  1275. exit 0
  1276.  
  1277.